package com.lagou.controller;

import com.lagou.dao.ResumeDao;
import com.lagou.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("resume")
public class ResumeController {

    @Autowired
    private ResumeDao resumeDao;

    // 查询所有
    @RequestMapping("list")
    public String queryAll(HttpServletRequest request, HttpServletResponse response,
                           ModelMap modelMap) {
        // 查询所有简历信息
        List<Resume> resumes = resumeDao.findAll();
        modelMap.addAttribute("resumes", resumes);
        return "list";
    }

    // 新增
    @RequestMapping("add")
    public String add(HttpServletRequest request, HttpServletResponse response) {

        Resume resume = new Resume();
        resume.setName("新增用户");
        resume.setAddress("新增地址");
        resume.setPhone("111111111");

        resumeDao.save(resume);
        // 重定向到登录页面
        return "redirect:/resume/list";
    }

    // 修改
    @RequestMapping("update")
    public String update(HttpServletRequest request, HttpServletResponse response, Integer id) {

        Resume resume = new Resume();
        resume.setId(new Long(id));
        resume.setName("修改用户");
        resume.setAddress("修改地址");
        resume.setPhone("22222222");

        resumeDao.save(resume);
        // 重定向到登录页面
        return "redirect:/resume/list";
    }

    // 删除
    // 修改
    @RequestMapping("delete")
    public String delete(HttpServletRequest request, HttpServletResponse response, Integer id) {
        Resume resume = new Resume();
        resume.setId(new Long(id));
        resumeDao.delete(resume);
        // 重定向到登录页面
        return "redirect:/resume/list";
    }
}
